#include "ClientDialog.h"
#include "ui_ClientDialog.h"

#include "client/ClientPlayer.h"
#include "core/global.h"

ClientDialog::ClientDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ClientDialog)
{
    ui->setupUi(this);

    ui->ipAddress->setText(Config.value("game/serverIPAddress").toString());
    ui->port->setText(Config.value("game/serverPort").toString());

    if(Config.contains("game/userName")){
        ui->userName->setText(Config.value("game/userName").toString());
    }
}

ClientDialog::~ClientDialog()
{
    Config.setValue("game/serverIPAddress", ui->ipAddress->text());
    Config.setValue("game/userName", ui->userName->text());
    delete ui;
}

void ClientDialog::on_buttonBox_accepted(){
    Self->setPlayerName(ui->userName->text());
    Self->connectToServer(ui->ipAddress->text(), ui->port->text().toUInt());
}
